import java.io._
import scala.collection.mutable

def write(value: AnyRef, message: String) {
  val out = new ObjectOutputStream(new ByteArrayOutputStream())
  try {
    out.writeObject(value)
    out.flush()
    println("...successful write of " + message)
  } catch {
    case ex => println("...failed write of " + message + ": " + ex)
  }
}

while (true) {
  print("Enter the length of the structure: ")
  val queue = new mutable.Queue[Int]()
  val size = readInt
  queue ++= (1 to size)
  write(queue, "recursive structure");
  val array = new Array(0) ++ (1 to size)
  write(array, "flat structure")
}
